//
//  ChargingCaseTableViewCell.swift
//  EasePods
//
//  Created by 易先生 on 2024/5/7.
//

import UIKit
import RxSwift
import RxCocoa
import Differentiator

class ChargingCaseTableViewCell: TableViewCell {

    override func makeUI() {
        super.makeUI()
        
        self.contentView.addSubview(titleLabel)
        self.contentView.addSubview(nextImageView)
        self.contentView.addSubview(contentLabel)
        
        titleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(25)
            make.leading.equalToSuperview().offset(20)
            make.centerY.equalToSuperview()
        }
        
        nextImageView.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-20)
            make.centerY.equalToSuperview()
        }
        
        contentLabel.snp.makeConstraints { make in
            make.trailing.equalTo(nextImageView.snp.leading).offset(-4)
            make.centerY.equalToSuperview()
        }

    }
    
    public func bind(to viewModel: ChargingCaseCellViewModel) {
        titleLabel.text = viewModel.cellType.title
        
        viewModel.contentRelay.subscribe(onNext: { [weak self] content in
            guard let self = self else { return }
            
            guard viewModel.cellType == .lockScreen else {
                self.contentLabel.text = content
                return
            }
            if let content = content {
                self.contentLabel.text = content + R.string.localizable.common_second()
            }
            
        }).disposed(by: rx.disposeBag)
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    private lazy var titleLabel: Label = {
        let label = Label()
        label.font = Fonts.systemFont(ofSize: 14)
        label.textColor = R.color.common_3_text()
        return label
    }()
    
    private lazy var contentLabel: Label = {
        let label = Label()
        label.font = Fonts.systemFont(ofSize: 14)
        label.textColor = R.color.common_11_text_list()
        return label
    }()
    
    private lazy var nextImageView: ImageView = {
        let imageView = ImageView()
        imageView.image = R.image.ic_common_list_more()
        return imageView
    }()

}

extension  ChargingCasecellType {
    
    var title: String {
        switch self {
        case .timeFormat:
            return R.string.localizable.setting_time_format_text()
        case .earCaseLanguage:
            return R.string.localizable.setting_ear_case_language_text()
        case .lockScreen:
            return R.string.localizable.setting_automatic_lock_screen_text()
        case .notification:
            return R.string.localizable.setting_message_text()
        case .contacts:
            return R.string.localizable.setting_contacts_text()
        case .none:
            return ""
        }
    }
}

extension TimeFormatCellType {
    
    var content: String {
        switch self {
        case .hours24:
            return R.string.localizable.setting_time_format_24_hour_text()
        case .hours12:
            return R.string.localizable.setting_time_format_12_hour_text()
        }
    }
    
}
